package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing/plan")
@Slf4j
@Api(tags = "服务计划管理相关接口")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    //删除服务计划
    @ApiOperation(value = "删除服务计划")
    @DeleteMapping("/{id}")
    public ResponseResult delete(@ApiParam(value = "服务计划id", required = true) @PathVariable("id") Long id) {
        log.info("删除服务计划,id:{}", id);
        nursingPlanService.delete(id);
        return success();
    }

    @GetMapping
    @ApiOperation("查询全部护理计划")
    public ResponseResult<List<NursingPlanVo>> getAllNursingPlan() {
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.getAllNursingPlan();
        return success(nursingPlanVos);
    }

    //根据id查询服务计划
    @ApiOperation(value = "根据id查询服务计划")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getNursingPlanById(@ApiParam(value = "服务计划id",required = true) @PathVariable("id") Long id){
        log.info("根据id查询服务计划,id:{}",id);
        NursingPlanVo nursingPlanVo = nursingPlanService.getNursingPlanById(id);

        return success(nursingPlanVo);
    }

    @ApiOperation(value = "分页查询服务计划")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> selectByPage(
            @ApiParam(value = "护理项目名称")  String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("分页查询护理计划列表：name={}, status={}, pageNum={}, pageSize={}", name, status, pageNum, pageSize);
        PageResponse<NursingPlanVo> pageInfo = nursingPlanService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);
    }

    @ApiOperation(value = "修改服务计划")
    @PutMapping("/{id}")
    public ResponseResult updateNursingPlan(@ApiParam(value = "服务计划信息") @RequestBody NursingPlanDto nursingPlanDto) {
        log.info("修改服务计划,nursingPlanDto:{}",nursingPlanDto);
        nursingPlanService.updateNursingPlan(nursingPlanDto);
        return success();
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理计划状态")
    public ResponseResult updateNursingPlanStatus(@PathVariable Long id,
                                                  @PathVariable Integer status) {
        log.info("修改护理计划状态：id {} status {}",id,status);
        nursingPlanService.updateNursingPlanStatus(id,status);
        return success();
    }
}